package logic

import (
	"context"
	"user-management/models/mysql"

	"user-management/userrpc/internal/svc"
	"user-management/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateLogic {
	return &UpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UpdateLogic) Update(in *userrpc.UpdateRequest) (*userrpc.UpdateResponse, error) {
	// todo: add your logic here and delete this line
	var user = mysql.User{
		Id:       int(in.Id),
		Username: in.Username,
		Password: in.Password,
	}
	mysql.DB.Debug().Where("id = ?", in.Id).Updates(&user)
	return &userrpc.UpdateResponse{
		Id: in.Id,
	}, nil
}
